package com.itcast.codec.obj.client.encoder;

import com.itcast.codec.obj.domain.User;
import com.itcast.codec.obj.util.HessianSerializerUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @program: bio_tcp
 * @description:
 * @author: zhanghz001
 * @create: 2021-02-23 08:53
 **/
public class HessianEncoder extends MessageToByteEncoder<User> {
    private HessianSerializerUtil serializer = new HessianSerializerUtil();
    
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext,
                          User user, ByteBuf byteBuf) throws Exception {
        //编码器
        byte[] bytes = serializer.serialize(user);
        byteBuf.writeBytes(bytes);
    }
}
